//
//  FP_UserPriceInquiryInfoCell.m
//  FootPad
//
//  Created by 张浩 on 2022/2/17.
//  Copyright © 2022 胶享悦. All rights reserved.
//

#import "MM_CodeResultStorageRackCell.h"

static const CGFloat addTitleTag = 200;

@interface MM_CodeResultStorageRackCell ()

@property (nonatomic, strong) UIView *baseView;

@end

@implementation MM_CodeResultStorageRackCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [ColorUtil colorWithHexadecimal:@"#ffffff"];
        [self.contentView addSubview:_baseView];
        
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.right.top.bottom.equalTo(self.contentView);
            make.height.equalTo(50);
        }];
        
    }
    return self;
}

- (void)setModel:(MM_CodeResultSkuLocationModel *)model {
    _model = model;
    
    NSArray *titleArr = @[[NSString stringWithFormat:@"%@\n%@",model.warehouse_name,model.warehouse_area_name],!stringIsEmpty(model.location_name)?[NSString stringWithFormat:@"%@\n%@",model.warehouse_area_property_str,model.location_name]:@"",!stringIsEmpty(model.shelf_number)?model.shelf_number:@"",!stringIsEmpty(model.layer_number)?model.layer_number:@"",!stringIsEmpty(model.roadway_number)?model.roadway_number:@"",!stringIsEmpty(model.available_qty)?model.available_qty:@"",@"操作"];
//    NSArray *titleWArr = @[@(9),@(7),@(7),@(5),@(5),@(6)];
    CGFloat titleW = ScreenW /7.0;
        
    for (UIView*subView in self.baseView.subviews) {
        
        [subView removeFromSuperview];
    }
    
    for (int i=0; i<titleArr.count; i++) {
        
        UIView *titleView = [[UIView alloc] init];
        titleView.backgroundColor = [ColorUtil colorWithHexadecimal:@"#ffffff"];
        titleView.tag = addTitleTag + i;
        [self.baseView addSubview:titleView];
        
        [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(titleW *i);
            make.top.height.equalTo(self.baseView);
            make.width.equalTo(titleW);
        }];
                
        UILabel *nameLabel = [Custom_ZHTool uiLabelCreate:titleArr[i] Font:FONT(12) TextColor:[ColorUtil colorWithHexadecimal:@"#333333"]];
        nameLabel.numberOfLines = 0;
        nameLabel.textAlignment = NSTextAlignmentCenter;
        nameLabel.textColor = [ColorUtil colorWithHexadecimal:@"#333333"];
        
        if (i == 6) {
            
            nameLabel.textColor = MM_ColorUtil(@"#DE1212");
        }
        
        [titleView addSubview:nameLabel];
        
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
//            if (i == 0 || i== 1) {
//                make.left.equalTo(12);
//                make.right.equalTo(-5);
//            }else {
//                make.left.equalTo(10);
//            }
            make.centerX.centerY.equalTo(titleView);
        }];
        
        if (i == titleArr.count - 1) {
            nameLabel.textColor = MM_ColorUtil(@"#DE1212");
            
            nameLabel.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(nameDataTapClick:)];
            [nameLabel addGestureRecognizer:tap1];
        }
        
//        UIView *lineView_1 = [[UIView alloc] init];
//        lineView_1.backgroundColor = [ColorUtil colorWithHexadecimal:@"#DDDDDD"];
//        [titleView addSubview:lineView_1];
//        
//        [lineView_1 mas_makeConstraints:^(MASConstraintMaker *make) {
//
//            make.right.top.equalTo(titleView);
////            make.top.equalTo(self.scrollView);
//            make.width.equalTo(0.5);
//            make.height.equalTo(76);
//        }];

//        UIView *lineView_2 = [[UIView alloc] init];
//        lineView_2.backgroundColor = [ColorUtil colorWithHexadecimal:@"#DDDDDD"];
//        [titleView addSubview:lineView_2];
//        
//        [lineView_2 mas_makeConstraints:^(MASConstraintMaker *make) {
//
//            make.left.top.equalTo(titleView);
////            make.top.equalTo(self.scrollView);
//            make.width.equalTo(titleW*[titleWArr[i] integerValue]);
//            make.height.equalTo(0.5);
//        }];
    }
}

- (void)nameDataTapClick:(UITapGestureRecognizer *)tap {
    
    if (self.changeBlock) {
        self.changeBlock(self.model);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
